package com.hewanglan.subject.infra.rpc;

import com.hewanglan.auth.api.entity.AuthUserDTO;
import com.hewanglan.auth.api.entity.Result;
import com.hewanglan.auth.api.service.UserFeignService;
import com.hewanglan.subject.infra.entity.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class UserRPC {

    @Resource
    private UserFeignService userFeignService;

    public UserInfo getUserInfo(String userName)
    {
        AuthUserDTO authUserDTO=new AuthUserDTO();
        authUserDTO.setUserName(userName);
        Result<AuthUserDTO> result = userFeignService.getUserInfo(authUserDTO);
        UserInfo userInfo=new UserInfo();
        if(!result.getSuccess())
        {
            return userInfo;
        }
        AuthUserDTO data = result.getData();
       userInfo.setUserName(data.getUserName());
       userInfo.setNickName(data.getNickName());
       userInfo.setAvatar(data.getAvatar());
       return userInfo;
    }


}
